package org.wiztools.te;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.KeyStroke;

class ErrorDialog extends JDialog{
	
	JTextArea jta;
	JDialog jd;
	
	ErrorDialog(JFrame jf, String title){
		super(jf, title);
		jd = this;
		Container ct = this.getContentPane();
		ct.setLayout(new BorderLayout());
		ct.add(new JLabel("Some Errors Occured:"), BorderLayout.NORTH);
		jta = new JTextArea();
		jta.setEditable(false);
		ct.add(new JScrollPane(jta), BorderLayout.CENTER);
		
		JPanel jp_south = new JPanel();
		JButton jb = new JButton("Ok");
		jb.setMnemonic('O');
		jb.addActionListener(
			new ActionListener(){
				public void actionPerformed(ActionEvent ae){
					jd.setVisible(false);
				}
			}
		);
		jp_south.add(jb);
		ct.add(jp_south, BorderLayout.SOUTH);
		this.setSize(300, 200);
		Point p = jf.getLocation();
		this.setLocation(p.x+(jf.getWidth()-this.getWidth())/2, p.y+(jf.getHeight()-this.getHeight())/2);
		this.setResizable(false);
	}
	
	void setErrString(String err){
		jta.setText(err);
	}
	
	protected JRootPane createRootPane() {
		ActionListener actionListener = new ActionListener() {
			public void actionPerformed(ActionEvent actionEvent) {
				setVisible(false);
			}
		};
		JRootPane rootPane = new JRootPane();
		rootPane.registerKeyboardAction(actionListener, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
		rootPane.registerKeyboardAction(actionListener, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
		return rootPane;
	}
}
